#include<vector>
using namespace std;
class Solution {
    bool col[9][10];
    bool row[9][10];
    bool grip[3][3][10];

public:
    void solveSudoku(vector<vector<char>>& board) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] != '.') {
                    int num = board[i][j] - '0';
                    row[i][num] = col[j][num] = grip[i / 3][j / 3][num] = true;
                }
            }
        }
        dfs(board);
    }
    bool dfs(vector<vector<char>>& board) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') {
                    for (int k = 1; k < 10; k++) {
                        if (check(i, j, k)) {
                            board[i][j] = k + '0';
                            row[i][k] = col[j][k] = grip[i / 3][j / 3][k] =
                                true;
                            if (dfs(board) == true) {
                                return true;
                            }
                            board[i][j] = '.';
                            row[i][k] = col[j][k] = grip[i / 3][j / 3][k] =
                                false;
                        }
                    }
                    return false;
                }
            }

        }
        return true;
    }

    bool check(int i, int j, int x) {
        return !(row[i][x] || col[j][x] || grip[i / 3][j / 3][x]);
    }
};